from dataclasses import dataclass
from typing import List, Tuple
import numpy as np

@dataclass
class BoundingBox:
    """边界框数据模型"""
    x1: float
    y1: float
    x2: float
    y2: float
    confidence: float
    class_id: int = 0
    
    @property
    def center(self) -> Tuple[float, float]:
        """返回边界框中心点"""
        return ((self.x1 + self.x2) / 2, (self.y1 + self.y2) / 2)
    
    @property
    def width(self) -> float:
        """返回边界框宽度"""
        return self.x2 - self.x1
    
    @property
    def height(self) -> float:
        """返回边界框高度"""
        return self.y2 - self.y1

@dataclass
class DetectionResult:
    """检测结果数据模型"""
    image_path: str
    boxes: List[BoundingBox]
    count: int
    processing_time: float
    confidence_threshold: float = 0.5
    
    def __post_init__(self):
        """后处理：确保count与boxes数量一致"""
        self.count = len(self.boxes)

@dataclass
class ImageInfo:
    """图像信息数据模型"""
    path: str
    filename: str
    size: Tuple[int, int]  # (width, height)
    is_processed: bool = False
    detection_result: DetectionResult = None
